package org.christopher.bank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.christopher.bank.entity.Employee;
import org.christopher.bank.mapper.EmployeeMapper;
import org.christopher.bank.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<Employee> selectEmployee() {
        return employeeMapper.selectEmployee();
    }

    @Override
    public Employee login(Employee employee) {

        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>(employee);

        return employeeMapper.selectOne(employeeQueryWrapper);
    }

    @Override
    public Employee selectEmployeeById(Integer id) {
        return employeeMapper.selectEmployeeById(id);
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public int addEmployee(Employee employee) {
        return employeeMapper.insert(employee);
    }

    @Override
    public int updateEmployee(Employee employee) {
        return 0;
    }

    @Override
    public int deleteEmployee(Integer id) {
        return employeeMapper.deleteById(id);
    }

}
